<template>
    <div>
        <h1>会员等级增加</h1>
        <table class="table table-bordered">
            <tbody >
                <tr>
                    <td>会员等级名称</td>
                    <td><input type="text" v-model="info.LevelName" /></td>
                </tr>
                <tr>
                    <td>累计消费金额</td>
                    <td><input type="text" v-model="info.Moeny" /></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="button" value="添加" class="btn btn-success" @click="addmen" /></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref, reactive } from 'vue'
import { useRouter } from 'vue-router';

const router = useRouter();
let info: any = reactive({
    "LevelName": '',
    "Moeny": ''
});
//声明一个变量来存储后端传递数据
const addmen = () => {
    if (info.LevelName == "") {
        alert("等级名称不能为空")
        return;
    }
    if (info.Moeny == "") {
        alert("消费金额不能为空")
        return;
    }
    axios({
        url: "/api/Menber/ManberAdd",
        method: "post",
        data: info,
    })
        .then(res => {
            console.log(res);
            if (res.data == -1) {
                alert("等级名称重复")
                return;
            }
            if (res.data > 0) {
                alert("添加成功")
                router.push('/menberLeveList')
                //跳转到显示列表
            }
            else {
                alert("添加失败")
            }
            //请求成功的成功
        }).catch(err => {

            //表示请求失败的结果
        });
};
</script>

<style scoped></style>